package com.interauto;

import com.interauto.Dao.Mapper.CaseStInter;
import com.interauto.Dao.Mapper.MgCaseRuntInter;
import com.interauto.Dao.Mapper.MgInteruntInter;
import com.interauto.Dao.entity.Caserunt;
import com.interauto.Dao.entity.Interunt;
import com.interauto.Interface.HttpAutoClientInterface;
import com.interauto.bean.AutoAssInfoBean;
import com.interauto.bean.AutoAssertInfoBean;
import com.interauto.bean.AutoCaseBean;
import com.interauto.bean.autoenum.AutoExpectEnum;
import com.interauto.bean.autoenum.HttpEnum;
import com.interauto.bean.web.RunTaskWeb;
import com.interauto.service.*;
import com.interauto.bean.httpinfo.HttpRequestBean;
import com.interauto.bean.httpinfo.HttpResPonseBean;
import com.interauto.service.web.RunTaskPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.ArrayList;
import java.util.Date;

@SpringBootApplication
@EnableScheduling
public class AppliCation {
    @Autowired
    private MgCaseRuntInter mgCaseRuntInter;
    @Autowired
    private MgInteruntInter mgInteruntInter;
    @Autowired
    private AutoCaseBeanService autoCaseBeanService;
    @Autowired
    private AutoRunResultService autoRunResultService;
    @Autowired
    private AutoRunCaseinfoService autoRunCaseinfoService;
    @Autowired
    private RunTaskPageService runTaskPageService;

    public void gogo() {
        HttpRequestBean httpinfo=new HttpRequestBean();
        httpinfo.setHttpurl("http://e.dangdang.com/media/api2.go?action=column&isFull=1&columnType=all_yuhuitaozhuang&end=0&start=0");
        httpinfo.setHttpmeth(HttpEnum.HttpMeth.POST);
    }

    public void uppcaserunt(){
        mgCaseRuntInter.upstatuscaserunt(5,2,new Date());
    }

    public void addcaserunt(){
        Caserunt caserunt=new Caserunt();
        caserunt.setCaseid(100);
        caserunt.setCasename("aaa");
        caserunt.setStatus(1);
        caserunt.setTaskid(200);
        mgCaseRuntInter.addcaserunt(caserunt);
        System.out.println(caserunt.toString());
    }

    public void addinterrunt(){
        Interunt interunt=new Interunt();
        interunt.setAutoassinfo("aaa");
        interunt.setCaseruntid(100);
        interunt.setStatus(1);
        interunt.setMessage("message");
        interunt.setHttpurl("http://www.baidu.com");
        interunt.setRestype(1);
        interunt.setIntercasetype(1);
        interunt.setInterfacename("aabb");
        interunt.setHttpcookie("a");
        interunt.setHttpheader("b");
        interunt.setHttpparam("c");

        interunt.setRestype(1);
        interunt.setRescode(200);
        interunt.setRescookie("a1");
        interunt.setResinfo("adfakds");
        interunt.setResheader("b1");
        mgInteruntInter.addinterrunt(interunt);
        System.out.println(interunt.toString());
    }


    public AutoCaseBean getautocaseinfo(int id){
        return autoCaseBeanService.getAutoCaseinfo(4);
    }

    public void runcaseauto(AutoCaseBean autoCaseBean){
        autoRunCaseinfoService.runcaseinfo(autoCaseBean,null);
    }


    public void addruntask(){
        RunTaskWeb a=new RunTaskWeb();
        a.setProjectid(100);
        a.setTaskname("任务2号");
        a.setCallemail("593901785@qq.com");
        a.setCallnumber("1250250");
        a.setRuncycle(20);
        a.setCaseinfo("a,b,c");
        System.out.println(runTaskPageService.addruntask(a));

    }

    public void upruntask(){
        runTaskPageService.goruntaskstatu(1,1);
    }


    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext ctx=new SpringApplicationBuilder(AppliCation.class).run(args);
        AppliCation appliCation=ctx.getBean("appliCation",AppliCation.class);
        //appliCation.addruntask();
//        AutoCaseBean autoCaseBean=appliCation.getautocaseinfo(4);
//        appliCation.runcaseauto(autoCaseBean);


        //AutoCaseBeanService caseStInter=ctx.getBean("autoCaseBeanService",AutoCaseBeanService.class);
        //System.out.println(caseStInter.getAutoCaseinfo(3).getAutoInterCaseBeans().get(0).getHttpRequestBean().toString());
//        AutoRunInterfaceService httpauto=ctx.getBean("autoRunInterfaceService", AutoRunInterfaceService.class);
//        HttpRequestBean httpinfo=new HttpRequestBean();
//        httpinfo.setHttpurl("http://e.dangdang.com/media/api2.go?action=column&isFull=1&columnType=all_yuhuitaozhuang&end=0&start=0");
//        httpinfo.setHttpMeth(HttpEnum.HttpMeth.GET);
//        ArrayList<AutoAssInfoBean> asslist=new ArrayList<>();
//        AutoAssInfoBean one=new AutoAssInfoBean();
//        one.setCheckinfo("$.data.total");
//        one.setExpectinfo("69");
//        one.setAutoExpectEnum(AutoExpectEnum.AssertContains);
//
//        AutoAssInfoBean two=new AutoAssInfoBean();
//        two.setCheckinfo("$.data.saleList[0].mediaList[0].authorPenname");
//        two.setExpectinfo("中岛1义道");
//        two.setAutoExpectEnum(AutoExpectEnum.AssertContains);
//        asslist.add(two);
//        HttpResPonseBean resinfo=httpauto.runifcase(httpinfo);
//        AutoAssertInfoBean infobean=httpauto.runcheckinfo(resinfo,asslist);
//        System.out.println(infobean);

    }
}
